package util;

public class QueryBuilder {
	
	static public String Build(String value, String wild, String connector, String table, String column, String optional){
		String[] values = QueryBuilder.ArrayBySpace(value);
		String query = " ( ";
		for(int a=0;a<values.length;a++){
			if(a>0)
				query += " "+connector+" ";
			if(values[a].equalsIgnoreCase(""))
				query += " ("+table+"."+column+" LIKE '' "+optional+") ";
			else
				query += " ("+table+"."+column+" LIKE '"+wild+values[a]+wild+"') ";
		}
		query += " ) ";
		return query;
	}
	static public String[] ArrayBySpace(String s){
		String[] sArray = new String[1];
		if( s == null){
			sArray[0] = "";
			return sArray;
		}
		sArray[0] = s.replace("  ", " ").replace("*", "%").trim();
		if(sArray[0].indexOf(" ")>=1){
			sArray = String.valueOf(sArray[0]).split(" ");
		}
		return sArray;
	}
}
